#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3e5 + 5;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int n, k;
char s[N];
int a[N];
bool check(int x) {  // a[i] >= x is satisfied
  int cnt = 0;
  bool f = false;
  rep(i, 1, n) {
    if (a[i] >= x) {
      if (s[i] == 'R') {
        if (f) cnt++, f = false;
      } else {
        f = true;
      }
    }
  }
  if (f) cnt++;
  return cnt <= k;
}
void solve() {
  cin >> n >> k;
  rep(i, 1, n) cin >> s[i];
  rep(i, 1, n) cin >> a[i];
  int l = 1, h = 1e9;
  while (l <= h) {
    int mid = (l + h) >> 1;
    if (check(mid))
      h = mid - 1;
    else
      l = mid + 1;
  }
  cout << h << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}